package defense.graphics;

import java.awt.Color;
import java.awt.Graphics2D;

import defense.GameObject;
import defense.physics.Vec2f;

public class Particle extends GameObject {
	Vec2f pos;
	Vec2f vel;
	float radius;
	float life;
	float lifeDecr;
	Color color;

	public Particle(Vec2f pos, Vec2f vel, float radius) {
		this.pos = new Vec2f(pos.x, pos.y);
		this.vel = new Vec2f(vel.x, vel.y);
		this.radius = radius;
		this.life = 1f;
		this.lifeDecr = 0.005f;
		this.color = Color.orange;
	}

	public void update() {
		vel.mult(0.93f);
		pos.add(vel);
		life -= lifeDecr;
	}

	boolean isDead() {
		return life <= 0;
	}

	public void display(Graphics2D g2d) {
		g2d.setColor(new Color(color.getRed() / 255.0f,
				color.getGreen() / 255.0f, color.getBlue() / 255.0f, life));
		g2d.fillOval((int) (pos.x - radius), (int) (pos.y - radius), (int) radius * 2,
				(int) radius * 2);
	}
}
